package com.ren.service;

import com.ren.dao.UserMapper;
import com.ren.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Zero on 2017/5/31.
 */
@Service("UserService")
public class UserServiceImpl implements UserService {


    @Autowired
    UserMapper userMapper;

    /**
     * 用户登录判断
     * @param username
     * @param password
     * @return
     */

    @Override
    public User findByUserNameAndPwd(String username, String password) {
        Map<String,Object> map = new HashMap<String, Object>();
        if (username != null && password != null){
            map.put("username",username);
            map.put("password",password);
        }
        return userMapper.selectByUserNameAndPwd(map);
    }

    /**
     * 注册判断
     * @param username
     * @return
     */
    @Override
    public User findUserByUserName(String username) {
        return userMapper.selectUserByUserName(username);
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Override
    public int addUser(User user) {
        return userMapper.insert(user);
    }
}
